//
//  LBTableViewCell.m
//  app
//
//  Created by 赵辉 on 16/6/20.
//  Copyright © 2016年 NAICAI LI. All rights reserved.
//

#import "LBTableViewCell.h"
#import <Masonry/Masonry.h>

@interface LBTableViewCell ()

@property (strong, nonatomic) UIView *lineView;

@end

@implementation LBTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUPUI];
    }
    return self;
}

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    [self setUPUI];
}

- (void)setUPUI
{
    [self addSubview:self.lineView];
}

- (void)setIsBottomLineHidden:(BOOL)isBottomLineHidden
{
    _isBottomLineHidden = isBottomLineHidden;
    [self.lineView setHidden:_isBottomLineHidden];
    if (!_isBottomLineHidden) {
        [self setLineLeftMargin:0 RightMargin:0];
    }
}

- (void)setLineLeftMargin:(CGFloat)leftMargin RightMargin:(CGFloat)rightMargin
{
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(leftMargin);
        make.right.mas_equalTo(self).offset(-rightMargin);
        make.height.mas_equalTo(1);
    }];
}

- (void)setLineLeftMargin:(CGFloat)leftMargin RightMargin:(CGFloat)rightMargin color:(UIColor *)color
{
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(leftMargin);
        make.right.mas_equalTo(self).offset(-rightMargin);
        make.height.mas_equalTo(1);
    }];
    if (color) {
        self.lineView.backgroundColor = color;
    }
}

#pragma mark - getter

- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithRed:243/255.0 green:244/255.0 blue:245/255.0 alpha:1];
        [_lineView setHidden:YES];
    }
    return _lineView;
}

@end
